<template>
	<view class="detail-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="内容详情"></uni-navbar></view>

		<view class="detail-info" v-if="detailInfo.id">
			<view class="info-title">
				<view class="title-top">{{ detailInfo.title }}</view>
				<view class="title-btm">
					<text class="btm-name">{{ detailInfo.createName }}</text>
					<text class="btm-time">{{ detailInfo.createTime | parseTime('{y}-{m}-{d}') }}</text>
				</view>
			</view>
			<view class="info-detail">
				<view class="info-h2">基本情况</view>
				<view class="overflow" v-html="detailInfo.content"></view>
			</view>
		</view>

		<view class="uploader-add" @click="onTts">
			<image v-if="!play" src="/static/img/icon_76.png" mode="widthFix"></image>
			<image src="/static/img/icon_77.gif" v-else mode="widthFix"></image>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			typeList: {},
			id: '',
			detailInfo: {}
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.id = option.id;
		this.loadData();
	},
	onHide() {
		this.$ttsOff();
	},
	onUnload() {
		this.$ttsOff();
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
			} else {
				this.$logout();
			}
		},
		loadDict(type, list) {
			this.$request('/system/sys-dict/dictList', {
				clientCode: this.clientCode,
				sysDict: {
					dictType: type
				}
			}).then((res) => {
				if (!res.data) {
					return false;
				}
				res.data.forEach((item) => {
					this[list][item.dictValue] = item.dictName;
				});
			});
		},
		loadData() {
			this.$request('/xieshangyishi/resm/query', {
				id: this.id
			}).then((res) => {
				this.detailInfo = res.data.resm;
				let reg = new RegExp('o:p', 'g');
				this.detailInfo.content = res.data.resm.content.replace(reg, 'p');
			});
		},
		tabsChange(index) {
			this.current = index;
		},
		onTts() {
			let text = this.detailInfo.title;
			text += ',' + this.detailInfo.createName;
			text += ',' + this.$parseTime(this.detailInfo.createTime, '{y}-{m}-{d}');
			text += ',' + this.$htmlRegx(this.detailInfo.content);
			this.$tts(text, this, 500);
		},
		previewImage(idx, images) {
			uni.previewImage({
				current: idx,
				urls: images
			});
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	background-color: #fff;
}

.form-box {
	border-top: 10rpx solid $u-border-color;

	.form-item {
		@include mp-flex;
	}
}

.fiexd-btm {
	position: static;
	border-top: 10rpx solid $u-border-color;
	padding: 30rpx;
}
</style>
